package com.common.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;
import java.util.Vector;

import org.apache.log4j.Logger;

import com.common.pager.PageHelper;
import com.common.util.BeanUtils;

public class DBBeanUtil {
	private final static int DEFAULT_PAGE_SIZE = 20;
	private static Logger log = Logger.getLogger(DBBeanUtil.class);
	
	
	public static Vector executePager4Obj(Object obj,String sql, PageHelper pager,Object...objects) throws NumberFormatException, Exception {
		pager.setTotalCount(Integer.parseInt(String.valueOf(execute(SqlUtil.getAnalyseSQLOfcount(sql),objects).get(0).get("count"))));
		return execute4Obj(obj,sql,pager.getRowPage(),pager.getCurrentPage(),pager.getTotalCount(),objects);
	}
	
	/**
	 * @param sql
	 * @param pagesize
	 * @param currentpage
	 * @param objects
	 * @return
	 */
	private static Vector execute4Obj(Object obj,String sql, int pagesize, int currentpage,int totalCount,Object...objects) {
		Vector ver = new Vector();
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		try {
			conn = DBSource.getConnection();
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();
			if(totalCount>0){
				// 将记录指针定位到待显示页的第一条记录上
				rs.absolute((currentpage - 1) * pagesize+1);
				int i = 0;
				while(!rs.isAfterLast()&&i < pagesize){
					Object o = new Object();
					Object newObj = obj.getClass().newInstance();
					for (int j = 0; j < columCount; j++) {
						String colunmName = rmd.getColumnName(j + 1);
						o = rs.getObject(colunmName);
						setProperty(newObj, o, colunmName);
					}
					ver.addElement(newObj);
					i++;
					rs.next();
				}
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, stmt, rs);
		}
		return ver;
	}
	
	/**
	 * @param sql
	 * @param pager
	 * @param objects
	 * @return
	 * @throws NumberFormatException
	 * @throws Exception
	 */
	public static Vector executePager4Map(String sql, PageHelper pager,Object...objects) throws NumberFormatException, Exception {
		pager.setTotalCount(Integer.parseInt((String)execute(SqlUtil.getAnalyseSQLOfcount(sql),objects).get(0).get("count")));
		return executePager4Map(sql,pager.getRowPage(),pager.getCurrentPage(),pager.getTotalCount(),objects);
	}
	
	/**
	 * @param sql
	 * @param pagesize
	 * @param currentpage
	 * @param objects
	 * @return
	 */
	private static Vector executePager4Map(String sql, int pagesize, int currentpage,int totalCount,Object...objects) {
		Vector ver = new Vector();
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		try {
			conn = DBSource.getConnection();
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();
			if(totalCount>0){
			// 将记录指针定位到待显示页的第一条记录上
				rs.absolute((currentpage - 1) * pagesize+1);
			int i = 0;
			while(!rs.isAfterLast()&&i < pagesize){
				Hashtable hash = new Hashtable();
				
				for (int j = 0; j < columCount; j++) {
					String colunmName = rmd.getColumnName(j + 1);
					Object rss = rs.getObject(colunmName);
					if(rss==null){
						rss="";
					}
					hash.put(colunmName, rss);
				}
				ver.addElement(hash);
				i++;
				rs.next();
			}
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, stmt, rs);
		}
		return ver;
	}
	
	public static Vector executeByConn4Obj(Connection conn,Object obj,String sql,Object...objects) {
		Vector ver = new Vector();
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		try {
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();
			int i = 0;
			while (rs.next() ) {
				i = i + 1;
				Object o = new Object();
				Object newObj = obj.getClass().newInstance();
				for (int j = 0; j < columCount; j++) {
					String colunmName = rmd.getColumnName(j + 1);
					o = rs.getObject(colunmName);
					setProperty(newObj, o, colunmName);
				}
				ver.addElement(newObj);
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					log.error(e.getMessage(),e);
				}
			}
			if (stmt != null) {
				try {
					stmt.close();
				} catch (SQLException e) {
					log.error(e.getMessage(),e);
				}
			}
		}
		return ver;
	}
	
	
	public static Vector executeByConn(Connection conn,String sql,Object...objects) {
		
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		Vector<Hashtable> vResult = new Vector<Hashtable>();
		try {
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();
			String[] columNames = new String[columCount];

			// 将记录指针定位到待显示页的第一条记录上
			int i = 0;
			while (rs.next() ) {
				i = i + 1;
				int idss = 0;
				Object o = new Object();
				Hashtable hRecord = new Hashtable();
				for (int j = 0; j < columCount; j++) {
					columNames[idss] = rmd.getColumnName(j + 1);
					o = rs.getObject(columNames[idss]);
					log.info(columNames[idss]+"======="+o);
					hRecord.put(columNames[idss], o);
				}
				vResult.addElement(hRecord);
				idss++;

				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (stmt != null) {
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
		return vResult;
	}
	public static Vector execute4Obj(Object obj,String sql,Object...objects) {
		Vector ver = new Vector();
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		try {
			conn = DBSource.getConnection();
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();
			int i = 0;
			while (rs.next() ) {
				i = i + 1;
				Object o = new Object();
				Object newObj = obj.getClass().newInstance();
				for (int j = 0; j < columCount; j++) {
					String colunmName = rmd.getColumnName(j + 1);
					o = rs.getObject(colunmName);
					setProperty(newObj, o, colunmName);
				}
				ver.addElement(newObj);
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, stmt, rs);
		}
		return ver;
	}
	
	/**
	 * 执行查询语句。 
	 * @param strSql 任何格式的查询语句
	 * @retrun Vector 对象,包含名/值对（hashtable格式类型）的结果
	 */
	public static Vector<Hashtable> execute4Map(String strSql) throws Exception {
		Connection conn = null;// 数据库联接
		Statement st = null;// 执行语句
		ResultSet rs = null;
		ResultSetMetaData rsmd = null;
		Vector<Hashtable> vResult = new Vector<Hashtable>();
		try {
			conn = DBSource.getConnection();// 取得数据联接
			st = conn.createStatement();// 创建执行语句
			rs = st.executeQuery(strSql);// 执行查询
			rsmd = rs.getMetaData(); // 元数据
			int nFieldCount = rsmd.getColumnCount();// 到得字段列数
			while (rs.next()) {
				Hashtable hRecord = new Hashtable();
				for (int k = 1; k <= nFieldCount; k++) {
					String strFieldName = rsmd.getColumnName(k);
					String strTemp = rs.getString(strFieldName);
					if (strTemp == null) {
						strTemp = "";
					}
					hRecord.put(strFieldName, strTemp);
				}
				vResult.addElement(hRecord);
			}
		} catch (SQLException sqle) {
			// 产生新的异常，则抛出新的程序异常
			log.error(sqle.getMessage(),sqle);
			throw new SQLException("sql 发生异常");
		} finally {
			close(rs, st, conn);
		}
		return vResult;// 返回值
	}
	
	
	/**
	 * @param sql
	 * @param pagesize
	 * @param currentpage
	 * @return
	 */
	public static Vector execute(String sql, int pagesize, int currentpage) {
		Vector ver = new Vector();
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		ResultSetMetaData rmd = null;
		try {
			conn = DBSource.getConnection();
			stmt = conn.createStatement(
					java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
					java.sql.ResultSet.CONCUR_READ_ONLY);
			rs = stmt.executeQuery(sql);
			rmd = rs.getMetaData();
			int columCount = rmd.getColumnCount();

			// 将记录指针定位到待显示页的第一条记录上
			rs.absolute((currentpage - 1) * pagesize);
			int i = 0;
			while (rs.next()&&i < pagesize ) {
				i = i + 1;
				Hashtable hash = new Hashtable();
				String rss = "";
				for (int j = 0; j < columCount; j++) {
					String colunmName = rmd.getColumnName(j + 1);
					rss = rs.getString(colunmName);
					if(rss==null){
						rss="";
					}
					hash.put(colunmName, rss);
				}
				ver.addElement(hash);
			}
		} catch (SQLException e) {
			log.error(e.getMessage(),e);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, stmt, rs);
		}
		return ver;
	}
	
	/**
	 * 执行insert update SQL。 单句时末尾无<b>。
	 * @return bRet 如果执行成功返回true，否则false。
	 * @param strSql 要执行的单句SQL或begin ...end语句。
	 */
	public static boolean executeUpdate(String strSql) throws Exception {
		boolean bRet = false;// 返回值
		Connection conn = null;// 数据库联接
		Statement st = null;// 执行语句
		try {
			conn = DBSource.getConnection();// 取得数据联接
			st = conn.createStatement();// 创建执行语句
			bRet = st.execute(strSql);
		} catch (SQLException sqle) {
			throw new SQLException("sql 发生异常");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage(),e);
			log.error(e.getMessage(),e);
		} finally {
			close(st, conn);
		}
		return bRet;// 返回值
	}
	/**
	 * @param strSql
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	public static boolean executeUpdate(String strSql,Object...objects) throws Exception {
		boolean bRet = false;// 返回值
		Connection conn = null;// 数据库联接
		PreparedStatement st = null;// 执行语句
		try {
			conn = DBSource.getConnection();// 取得数据联接
			st = conn.prepareStatement(strSql);// 创建执行语句
			for (int i = 0; i < objects.length; i++) {
				int n = i+1;
				setStatemnt(st, n, objects[i]);
			}
			bRet = st.execute();
		} catch (SQLException sqle) {
			log.error(sqle.getMessage(),sqle);
			throw new SQLException("sql 发生异常");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage(),e);
		} finally {
			close(st, conn);
		}
		return bRet;// 返回值
	}
	/**
	 * @param sql
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	public static boolean executeBatchUpdate(String sql,Object...objects) throws Exception {
		boolean bRet = false;// 返回值
		Connection conn = null;// 数据库联接
		PreparedStatement st = null;// 执行语句
		try {
			conn = DBSource.getConnection();// 取得数据联接
			st = conn.prepareStatement(sql);// 创建执行语句
			for (int i = 0; i < objects.length; i++) {
				int n = i+1;
				setStatemnt(st, n, objects[i]);
				st.addBatch();
			}
			st.executeBatch();
			return true;
		} catch (SQLException sqle) {
			log.error(sqle.getMessage(),sqle);
			throw new SQLException("sql 发生异常");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error(e.getMessage(),e);
		} finally {
			close(st, conn);
		}
		return bRet;// 返回值
	}
	
	/**
	 * @param strSql
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	public static boolean executeUpdateByConn(Connection conn,String strSql,Object...objects) throws Exception {
		
		
		boolean bRet = false;// 返回值
		PreparedStatement st = null;// 执行语句
		try {
			st = conn.prepareStatement(strSql);// 创建执行语句
			for (int i = 0; i < objects.length; i++) {
				int n = i+1;
				setStatemnt(st, n, objects[i]);
			}
			bRet = st.execute();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			throw new SQLException("sql 发生异常");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			close(st);
		}
		return bRet;// 返回值
		
	}
	/**
	 * @param strSql
	 * @param objects
	 * @return
	 * @throws Exception
	 */
	public static Vector<Hashtable> execute(String strSql, Object... objects ) throws Exception {
		Connection conn = null;// 数据库联接
		PreparedStatement st = null;// 执行语句
		ResultSet rs = null;
		ResultSetMetaData rsmd = null;
		Vector<Hashtable> vResult = new Vector<Hashtable>();
		try {
			conn = DBSource.getConnection();// 取得数据联接
			st = conn.prepareStatement(strSql);// 创建执行语句
			for(int i=0;i<objects.length;i++){
				int n = i+1;
				setStatemnt(st, n, objects[i]);
			}
			rs = st.executeQuery();// 执行查询
			rsmd = rs.getMetaData(); // 元数据
			int nFieldCount = rsmd.getColumnCount();// 到得字段列数
			while (rs.next()) {
				Hashtable hRecord = new Hashtable();
				for (int k = 1; k <= nFieldCount; k++) {
					String strFieldName = rsmd.getColumnName(k);

					Object strTemp = rs.getObject(strFieldName);
					if (strTemp == null) {
						strTemp = "";
					}
					hRecord.put(strFieldName, strTemp);
				}
				vResult.addElement(hRecord);
			}
		} catch (SQLException sqle)
		{
			log.error(sqle.getMessage(),sqle);
			// 产生新的异常，则抛出新的程序异常
			throw new SQLException("sql 发生异常");
		} finally {
			close(rs, st, conn);
		}
		return vResult;// 返回值

	}
	
	public static Object getObjectSingle(String sql,Object...objects) {
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		Object strRet = 0;
		try {
			conn = DBSource.getConnection();
			stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
			for(int i=0;i<objects.length;i++){
				int n=i+1;
				setStatemnt(stmt, n, objects[i]);
			}
			rs = stmt.executeQuery();
			if (rs.next())
			strRet = rs.getObject(1);
		} catch (SQLException sqle) {
			log.error(sqle.getMessage(),sqle);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, stmt, rs);
		}
		return strRet;
	}
	/**
	 * @param strSql
	 * @return
	 * @throws Exception
	 */
	public static String getSingle(String strSql) throws Exception {
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		String strRet = "";
		try {
			conn = DBSource.getConnection();
			st = conn.createStatement();
			rs = st.executeQuery(strSql);
			if (rs.next())
				strRet = rs.getString(1);
		} catch (SQLException sqle) {
			throw new SQLException("sql 发生异常");
		} finally {
			closeConnection(conn, st, rs);
		}
		return strRet;
	}

	/**
	 * @param strSql
	 * @return
	 * @throws Exception
	 */
	public static int getIntSingle(String strSql) throws Exception {
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		int strRet = 0;
		try {
			conn = DBSource.getConnection();
			st = conn.createStatement();
			rs = st.executeQuery(strSql);
			if (rs.next())
				strRet = rs.getInt(1);
		} catch (SQLException sqle) {
			throw new SQLException("sql 发生异常");
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		} finally {
			closeConnection(conn, st, rs);
		}
		return strRet;
	}





	public synchronized static String getKeyVal(String tablename){
		StringBuffer sql = new StringBuffer("select max(id) as id from "+tablename+"");
		try {
			Vector v = execute(sql.toString());
			Hashtable obj= (Hashtable)v.get(0);
			long keyval = Long.parseLong((String)obj.get("id"));
			
			return String.valueOf(keyval+1);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
		return "";
		
	}

	public static void main(String[] args) throws Exception {

		// DBBean db=new DBBean();

		/*
		 * String s="Select Count(*) from jxs"; String i=DBBean.getSingle(s);
		 * System.out.println("i="+i);
		 * 
		 * 
		 * String sql="select * from menu2"; sql="select top 2 * from menu2
		 * minus select top 1 * from menu2 "; Vector v=DBBean.execute(sql);
		 * System.out.println("v="+v);
		 * 
		 * 
		 * String insertsql="insert into test (username,password,hits) values
		 * (3,3,3)"; String updatesql="update test set hits=hits+1 where id=4";
		 * String deletesql="delete test where id=4";
		 * //DBBean.executeSql(updatesql); //DBBean.executeSql(insertsql);
		 * //DBBean.executeSql(deletesql);
		 */
		/*for (int k = 0; k < 100; k++) {
			int keyvalue = DBBeanUtil.getKeyValue("test");
			System.out.println("key" + (k + 1) + "===keyvalue=" + keyvalue);
		}
*/
	}



	
	/**
	 * @param sql
	 * @param pager
	 * @param objects
	 * @return
	 * @throws NumberFormatException
	 * @throws Exception
	 */
/*	public static Vector execute(String sql, PageHelper pager,Object...objects) throws NumberFormatException, Exception {
		pager.setTotalCount(Integer.parseInt((String)execute(SqlUtil.getAnalyseSQLOfcount(sql),objects).get(0).get("count")));
		return execute(sql,pager.getRowPage(),pager.getCurrentPage(),objects);
	}*/
	
	/**
	 * <p>
	 * 关闭Connection连接,ResultSet,Statement
	 * </p>
	 */
	public static void closeConnection(Connection conn, Statement stmt, ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				log.error(e.getMessage(),e);
			}
		}
		if (stmt != null) {
			try {
				stmt.close();
			} catch (SQLException e) {
				log.error(e.getMessage(),e);
			}
		}
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				System.out.println("连接关闭失败。可能连接未创建成功！" + e.getMessage());
			}
		} else {
			System.out.println("=> [Connection未创建，无法关闭]");
		}

	}
	
	/**
	 * 关闭ResultSet、Statement和Connection
	 * @param rs ResultSet to be closed
	 * @param stmt Statement or PreparedStatement to be closed
	 * @param conn Connection to be closed
	 */
	public static void close(ResultSet rs, Statement stmt, Connection conn) {
		if (rs != null)
			try {
				rs.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
		if (stmt != null)
			try {
				stmt.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
		if (conn != null)
			try {
				conn.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
	}
	public static void close(ResultSet rs, Statement stmt) {
		if (rs != null)
			try {
				rs.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
		if (stmt != null)
			try {
				stmt.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
		
	}

	public static void close(Statement stmt, Connection conn) {
		if (stmt != null)
			try {
				stmt.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
		if (conn != null)
			try {
				conn.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
	}

	public static void close(PreparedStatement pstmt, Connection conn) {
		try {
			if (pstmt != null)
				pstmt.close();
		} catch (Exception e) {
			// logger.error(e);
		}
		if (conn != null)
			try {
				conn.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
	}

	public static void close(PreparedStatement pstmt) {
		try {
			if (pstmt != null)
				pstmt.close();
		} catch (Exception e) {
			log.error(e);
		}
	}

	public static void close(Connection conn) {
		if (conn != null)
			try {
				conn.close();
			} catch (java.sql.SQLException ex) {
				ex.printStackTrace();
			}
	}
	
//	**********private*********
	private static void setPropertyVO(Object newObj,Object columObj,String propertyName) throws NoSuchFieldException{
		if(columObj!=null){
			propertyName = propertyName.toLowerCase();
			String[] str = propertyName.split("_");
			for(int i=0;i<str.length;i++){
				if(i==0){
					propertyName=str[i];
				}else{
					propertyName+=(str[i].substring(0,1).toUpperCase()+str[i].substring(1));
				}
			}
			BeanUtils.forceSetProperty(newObj, propertyName,columObj);
		}
	}
	private static void setProperty(Object newObj,Object columObj,String propertyName) throws NoSuchFieldException{
		if(columObj!=null){
			
			BeanUtils.forceSetProperty(newObj, propertyName,columObj);
		}
	}
	private static void setProperty4Table(Object newObj,Object columObj,String propertyName) throws NoSuchFieldException{
		if(columObj!=null){
			BeanUtils.forceSetProperty(newObj, SqlUtil.db2ObjStr(propertyName),columObj);
		}
	}
	
	private static void setStatemnt(PreparedStatement stmt,int n,Object o) throws SQLException{
		stmt.setObject(n, o);
	}
}
